/***************************************************************************
创建者：华磊
 开始时间：               : 2020.1１.09
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   顶部视窗测试用代理类
*                                                                         *
 ***************************************************************************/
#include "topviewdelegate.h"
#include <QDebug>
#include "hmicommondefine.h"
#include "instructionEnum.h"

#include "../CommunicateDelegate/filedata.h"
#include <QMessageBox>
#include "communicatenormaldelegate.h"
extern FileData fileData;


TopViewDelegate::TopViewDelegate(TopView *topViewIn, GlobalData *globalDataIn,
                                 GlobalData *ioDataIn, CommunicateNormalDelegate *communicateNormalIn, QObject* parent):QObject(parent)
{
    globalData = globalDataIn;
    ioData=ioDataIn;
    topView=topViewIn;
    communicateNormal=communicateNormalIn;
    timerUpdate = new QTimer;
    connect(timerUpdate,SIGNAL(timeout()),this,SLOT(timeUpdateWork()));
    tmpConnected = -1;
    initConnect();
    initialValue();
    timerUpdate->start(TOP_UPDATE);
}

void TopViewDelegate::initConnect()
{
    connect(topView->changeSpeedView,SIGNAL(changeAutoSpeed()),this,SLOT(changeAutoSpeedSlot()));
    connect(topView->changeSpeedView,SIGNAL(changeMaunalSpeed()),this,SLOT(changeMaunalSpeedSlot()));
    connect(topView->changeSpeedView,SIGNAL(reduceAutoSpeed()),this,SLOT(reduceAutoSpeedSlot()));
    connect(topView->changeSpeedView,SIGNAL(reduceMaunalSpeed()),this,SLOT(reduceMaunalSpeedSlot()));
    connect(topView->changeSpeedView,SIGNAL(sliderAutoSpeed(int)),this,SLOT(sliderAutoSpeedSlot(int)));
    connect(topView->changeSpeedView,SIGNAL(sliderMaunalSpeed(int)),this,SLOT(sliderMaunalSpeedSlot(int)));

    connect(topView->currentCoordinateView,SIGNAL(changeCurrentToolCoordinate(int)),this,SLOT(changeCurrentToolCoordinateSlot(int)));
    connect(topView->currentCoordinateView,SIGNAL(changeCurrentUserCoordinate(int)),this,SLOT(changeCurrentUserCoordinateSlot(int)));
    connect(topView->currentCoordinateView,SIGNAL(ipoModeFanuc()),this,SLOT(ipoModeFanucSlot()));
    connect(topView->currentCoordinateView,SIGNAL(ipoModeExtra()),this,SLOT(ipoModeExtraSlot()));

    connect(topView->debugModeView,SIGNAL(changeStepDebugMode()),this,SLOT(changeStepDebugModeSlot()));
    connect(topView->debugModeView,SIGNAL(changeContinueDebugMode()),this,SLOT(changeContinueDebugModeSlot()));

    connect(topView->controlModeView,SIGNAL(controlMaunal1Mode()),this,SLOT(controlMaunal1ModeSlot()));
    connect(topView->controlModeView,SIGNAL(controlMaunal2Mode()),this,SLOT(controlMaunal2ModeSlot()));
    connect(topView->controlModeView,SIGNAL(controlAutoMode()),this,SLOT(controlAutoModeSlot()));
    connect(topView->controlModeView,SIGNAL(controlExtraMode()),this,SLOT(controlExtraModeSlot()));
    // 关联FLEET 调度控制模式响应槽函数
    connect(topView->controlModeView,SIGNAL(controlFleetMode()), this, SLOT(controlFleetModeSlot()));

    connect(topView->jogCoordinateView,SIGNAL(changeJointCoordinate()),this,SLOT(changeJointCoordinateSlot()));
    connect(topView->jogCoordinateView,SIGNAL(changeUserCoordinate()),this,SLOT(changeUserCoordinateSlot()));
    connect(topView->jogCoordinateView,SIGNAL(changeToolCoordinate()),this,SLOT(changeToolCoordinateSlot()));
    connect(topView->jogCoordinateView,SIGNAL(changeWorldCoordinate()),this,SLOT(changeWorldCoordinateSlot()));

    connect(topView->robotListView,SIGNAL(showRobotList()),this,SLOT(showRobotListSlot()));
    connect(topView->robotListView,SIGNAL(showFileName()),this,SLOT(showFileNameSlot()));
    connect(topView->robotListView->changeRobotDialog,SIGNAL(changeRobotSiganl(int)),this,SLOT(changeRobotSlot(int)));

    connect(topView,SIGNAL(homeMenu() ),this,SLOT(homeMenuSlot()));
    connect(topView,SIGNAL(changeAccount()),this,SLOT(changeAccountSlot()));
    connect(topView->robotListView,SIGNAL(showMultiRobotControlDlg_signal()),this,SLOT(showMultiRobotControlDlg_slot()));

    connect(topView,SIGNAL(updateRobotListView_signal()),this,SLOT(initialRobotList_slot()));


    //connect(topView,SIGNAL(showWindowStatus()),this,SLOT(showWindowStatusSlot()));//不再使用
    //topView->windowStatusSignal();//蓝色框的刷新,为何这样写???-现注释,不使用,统一在定时器更新
    //定时dlegate刷新date,提示view更新
    connect(this,SIGNAL(timerUpdateViewSignal()),topView,SLOT(updateAllChildView()));
}

void TopViewDelegate::increaseVel(double &vel)
{
    if(vel<=8)
    {
        vel+=1.5;
    }
    else if(vel<=30)
    {
        vel+=8;
    }
    else if(vel<=6)
    {
        vel+=10;
    }
    else
    {
        vel+=12;
    }

    if(vel>100)
    {
        vel=100;
    }
}

void TopViewDelegate::decreaseVel(double &vel)
{
    if(vel<=8)
    {
        vel-=1.5;
    }
    else if(vel<=30)
    {
        vel-=8;
    }
    else if(vel<=60)
    {
        vel-=10;
    }
    else
    {
        vel-=12;
    }

    if(vel<=0)
    {
        vel=1;
    }
}

TopViewDelegate::~TopViewDelegate()
{

}

void TopViewDelegate::initialRobotList_slot()
{
    //已经初始化机器人列表
    std::vector<CommRobotInfo> robotInfoListOut;
    globalData->getRobotInfoList(robotInfoListOut);
    topView->robotLineID = globalData->currentRobotID;
    topView->robotList.resize(robotInfoListOut.size());
    for(int i = 0;i<topView->robotList.size();i++)
    {
        topView->robotList[i].RobotId = robotInfoListOut[i].robotId;
        topView->robotList[i].RobotName = QString::fromStdString(robotInfoListOut[i].robotName);

    }
    topView->robotListView->updateRobotView();
}

void TopViewDelegate::velIncrease_slot()
{
    double tmpSpeed;
    switch(globalData->globalHandState)
    {
    case EM_CONTROL_MODE_T1:
    case EM_CONTROL_MODE_T2:
    {
        tmpSpeed=globalData->globalManSpeed;
        increaseVel(tmpSpeed);
        emit setManSpeedToServerSignal(tmpSpeed);

    }
        break;
    case EM_CONTROL_MODE_AUTO:
    case EM_CONTROL_MODE_EXT:
    case EM_CONTROL_MODE_FLEET:
    {
        tmpSpeed=globalData->globalProSpeed;
        increaseVel(tmpSpeed);
        emit setAutoSpeedToServerSignal(tmpSpeed);
    }
    }



}

void TopViewDelegate::velDecrease_slot()
{

    double tmpSpeed;
    switch(globalData->globalHandState)
    {
    case EM_CONTROL_MODE_T1:
    case EM_CONTROL_MODE_T2:
    {
        tmpSpeed=globalData->globalManSpeed;
        decreaseVel(tmpSpeed);
        emit setManSpeedToServerSignal(tmpSpeed);

    }
        break;
    case EM_CONTROL_MODE_AUTO:
    case EM_CONTROL_MODE_EXT:
    case EM_CONTROL_MODE_FLEET:
    {
        tmpSpeed=globalData->globalProSpeed;
        decreaseVel(tmpSpeed);
        emit setAutoSpeedToServerSignal(tmpSpeed);
    }
    }


}

void TopViewDelegate::stepModeChange_slot()
{
    switch(globalData->globalHandRunStatus)
    {
    case 0:
    {
        emit setDebugRunModeSignal(1);
    }
        break;
    case 1:
    {
        emit setDebugRunModeSignal(0);
    }
    }

}

void TopViewDelegate::jogCoordinateChange_slot()
{
    switch(globalData->globalCoordinate)
    {
    case EM_JOG_COORDINATE_JOINT:
    {
        emit setJointCoordinateSignal(EM_JOG_COORDINATE_TOOL);
    }
        break;
    case EM_JOG_COORDINATE_TOOL:
    {
        emit setJointCoordinateSignal(EM_JOG_COORDINATE_USER);
    }
        break;
    case EM_JOG_COORDINATE_USER:
    {
        emit setJointCoordinateSignal(EM_JOG_COORDINATE_WORLD);
    }
        break;
    case EM_JOG_COORDINATE_WORLD:
    {
        emit setJointCoordinateSignal(EM_JOG_COORDINATE_JOINT);
    }
        break;
    }
}

void TopViewDelegate::jogCoordinateChangeTool_slot()
{
    emit setJointCoordinateSignal(EM_JOG_COORDINATE_TOOL);
}

void TopViewDelegate::robotChange_slot()
{
    emit showMultiRobotControlDlg_signal();
}

void TopViewDelegate::servoOn_slot(int isOn)
{
//    static bool tmpOn=false;
    switch(globalData->globalHandState)
    {
    case EM_CONTROL_MODE_T1:
    case EM_CONTROL_MODE_T2:
    {
        if(EM_MOTOR_STATUS_SERVO_ON==globalData->globalServoState)
        {
            emit manualChangeSignal(0);
        }
        else
        {
            emit manualChangeSignal(1);
        }


    }
        break;
    case EM_CONTROL_MODE_AUTO:
    case EM_CONTROL_MODE_EXT:
    case EM_CONTROL_MODE_FLEET:
    {
        emit manualChangeSignal(1);
    }
    }

//    globalData->globalServoState

}

void TopViewDelegate::timeUpdateWork()
{
//    static int robotIdStatic=-1;
    if(globalData)
    {
        //qDebug()<<"TopViewDelegate1";
//        if(globalData->tryLock() )
//        {
            //qDebug()<<"TopViewDelegate2";
            if(globalData->globalLoginStatus)
            {
                //更新一般信息显示
                topView->autoSpeed = globalData->globalProSpeed;
                topView->maunalSpeed = globalData->globalManSpeed;
                topView->debugMode = globalData->globalHandRunStatus;
                topView->jogCoordinate = globalData->globalCoordinate;
                topView->controlMode = globalData->globalHandState;
                if(topView->controlMode >= EM_CONTROL_MODE_AUTO)//自动或者外部
                {
                    topView->debugMode = 2;//无效
                }
                topView->currentToolCoordinate = globalData->globalDefaultToolNum;
                topView->currentUserCoordinate = globalData->globalDefaultUserNum;

//                //机器人切换判断
//                if(robotIdStatic!=globalData->currentRobotID)
//                {
//                    robotIdStatic=globalData->currentRobotID;
//                }



                topView->account = globalData->getUserInfo().account;        //权限状态
                topView->motorStatus = globalData->globalServoState;    //伺服状态
                if(globalData->controllerIsConnected == EM_CONNECT_SUCCESS)
                {
                    topView->shortMessage = QString::fromStdString(globalData->getCurrentTime());
                    tmpConnected = EM_CONNECT_SUCCESS;
                }
                else
                {
                    topView->shortMessage=tr("连接断开");
                    if(tmpConnected == EM_CONNECT_SUCCESS)
                    {
                        tmpConnected = -1;

                        #ifdef BUILD_ARM
                        emit setBuzzerPlay_signal();
//                        system("/bin/app_pwm");
//                        system("/bin/app_pwm");
//                        system("/bin/app_pwm");
                        #endif
                        //globalData->unlock();
                        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("与控制器的连接断开!请尝试重新登录..."));
                        //return;
                    }
                }

                topView->longMessage = "";

                if(EM_UPDATE_STATUS_LV2 == globalData->initCtrlState)
                {
                    if(EM_UPDATE_STATUS_LV2 == globalData->initHmiState)//2017.05.03 补充
                    {
                        std::vector<Message> messageVectorOut;
                        globalData->getMessageVector(messageVectorOut);
                        if(messageVectorOut.size() > 0)
                        {
                            topView->isLongMsg = true;
                            topView->longMessage = QString::fromStdString(messageVectorOut[messageVectorOut.size()-1].MessageInformation);
                        }
                        else
                        {
                            topView->isLongMsg = false;
                            topView->longMessage = tr("欢迎使用HMI软件！ ");
                        }
                    }
                    else//2017.05.03 补充
                    {
                        topView->isLongMsg = true;
                        if(EM_UPDATE_STATUS_LV1 == globalData->initHmiState)
                        {
                            topView->longMessage = tr("HMI正在初始化,无法操作!请稍后! ");
                        }
                        else if(-1 == globalData->initHmiState)
                        {
                            topView->longMessage = tr("HMI系统时间正在初始化,无法操作!请稍后! ");
                        }
                        else if(-2 == globalData->initHmiState)
                        {
                            topView->longMessage = tr("HMI坐标系信息正在初始化,无法操作!请稍后! ");
                        }
                        else if(-3 == globalData->initHmiState)
                        {
                            topView->longMessage = tr("HMI文件系统正在初始化,无法操作!请稍后! ");
                        }
                        else if(-4 == globalData->initHmiState)
                        {
                            topView->longMessage = tr("HMI正在读取文件信息,无法操作!请稍后! ");
                        }
                        else if(-5 == globalData->initHmiState)
                        {
                            topView->longMessage = tr("IO信息正在初始化,无法操作!请稍后! ");
                        }
                    }
                }
                else
                {
                    topView->isLongMsg = true;
                    topView->longMessage = tr("控制器正在初始化,无法操作!请稍后! ");
                }

                //即使是缺省文件,开机时候也会立刻打开,显示为当前文件

                topView->fileName= fileData.currentFileName;



            }


        topView->updateCurrentRobotName(QString::fromStdString(globalData->getCurrentRobotName()));
        emit timerUpdateViewSignal();//way1 信号

    }

    if(!topView->changeSpeedView->isHidden())
    {
        topView->changeSpeedView->updateAutoAdd();
        topView->changeSpeedView->updateMaunalAdd();
    }

}

void TopViewDelegate::showMultiRobotControlDlg_slot()
{
    emit showMultiRobotControlDlg_signal();

}



void TopViewDelegate::changeAutoSpeedSlot()//自动加速度
{
    //qDebug()<<"autospeedadd";
    float currentSpeed = topView->autoSpeed;
    if(currentSpeed<100)
    {
        if(currentSpeed<2)
        {
            currentSpeed = currentSpeed + 0.1;
        }
        else
        {
            currentSpeed++;
        }
        emit setAutoSpeedToServerSignal(currentSpeed);
    }
}

void TopViewDelegate::reduceAutoSpeedSlot()//自动减速度
{
    float currentSpeed = topView->autoSpeed;
    //qDebug()<<"autospeedreduce "<<QString::number(currentSpeed,'f',4);

    if(currentSpeed>0)
    {
        if(currentSpeed<=2)
        {
            if( QString::number(currentSpeed,'f',1) == "0.1" )
            {
                return;
            }
            currentSpeed = currentSpeed - 0.1;
        }
        else
        {
            currentSpeed--;
        }
        emit setAutoSpeedToServerSignal(currentSpeed);
    }
}

void TopViewDelegate::changeMaunalSpeedSlot()//手动加速度
{
    //qDebug()<<"maunalspeedadd";
    float currentSpeed = topView->maunalSpeed;
    if(currentSpeed<100)
    {
        if(currentSpeed<2)
        {
            currentSpeed = currentSpeed + 0.1;
        }
        else
        {
            currentSpeed++;
            //qDebug()<<"maunalspeedreduece "<<currentSpeed;
        }
        emit setManSpeedToServerSignal(currentSpeed);
    }
}

void TopViewDelegate::reduceMaunalSpeedSlot()//手动减速度
{
    float currentSpeed = topView->maunalSpeed;
    //qDebug()<<"maunalspeedreduece "<<QString::number(currentSpeed,'f',1);

    if(currentSpeed>0)
    {
        if(currentSpeed<=2)
        {
            if( QString::number(currentSpeed,'f',1) == "0.1" )
            {
                return;
            }
            currentSpeed = currentSpeed - 0.1;
        }
        else
        {
            currentSpeed--;
            //qDebug()<<"maunalspeedreduece "<<currentSpeed;
        }
        emit setManSpeedToServerSignal(currentSpeed);
    }
}

void TopViewDelegate::sliderAutoSpeedSlot(int speed)//滑动条
{
    emit setAutoSpeedToServerSignal((float)speed);
}

void TopViewDelegate::sliderMaunalSpeedSlot(int speed)//滑动条
{
    emit setManSpeedToServerSignal((float)speed);
}

void TopViewDelegate::changeStepDebugModeSlot()//单步
{
    //qDebug()<<"stepdebugmode";
    emit setDebugRunModeSignal(EM_DEBUG_MODE_STEP);
}

void TopViewDelegate::changeContinueDebugModeSlot()//连续
{
    //qDebug()<<"continuedebugmode";
    emit setDebugRunModeSignal(EM_DEBUG_MODE_CONTINUE);
}


void TopViewDelegate::changeCurrentToolCoordinateSlot(int currentIndex)
{
    //qDebug()<<"toolcoordinate";
    //qDebug()<<currentIndex;
    if(currentIndex==globalData->globalDefaultToolNum)
    {
        return;
    }
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState != ENUM_COMMAND_RUN && globalData->globalCurrentState != ENUM_COMMAND_CEASE)
        {
//            globalData->unlock();
            emit setCurrentToolCoordSianal(currentIndex);
        }
        else
        {
//            globalData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请停止程序再切换工具坐标系号"));
        }
//    }
}

void TopViewDelegate::changeCurrentUserCoordinateSlot(int currentIndex)
{
    //qDebug()<<"usercoordinate";
    if(currentIndex==globalData->globalDefaultUserNum)
    {
        return;
    }
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState != ENUM_COMMAND_RUN && globalData->globalCurrentState != ENUM_COMMAND_CEASE)
        {
//            globalData->unlock();
            emit setCurrentUserCoordSianal(currentIndex);
        }
        else
        {
//            globalData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请停止程序再切换用户坐标系号"));
        }
//    }
}

void TopViewDelegate::ipoModeFanucSlot()//法兰
{
    //qDebug()<<"ipomodefanuc";
    topView->ipoModeFlag=0;
}

void TopViewDelegate::ipoModeExtraSlot()//外部
{
    //qDebug()<<"ipomodeextra";
    topView->ipoModeFlag=1;
}


void TopViewDelegate::controlMaunal1ModeSlot()//运行模式
{
    //qDebug()<<"maunal1mode";
    if(EM_CONTROL_MODE_T1==globalData->globalHandState)
    {
        return;
    }

//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState != ENUM_COMMAND_RUN && globalData->globalCurrentState != ENUM_COMMAND_CEASE)
        {
            emit setControlMaunalMode(EM_CONTROL_MODE_T1);

//            if(globalData->globalHandState == EM_CONTROL_MODE_AUTO || globalData->globalHandState == EM_CONTROL_MODE_EXT)
//            {
//                emit manualChangeSignal(0);//关闭使能
//            }
//            globalData->unlock();
        }
        else
        {
//            globalData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请停止程序再切换T1模式"));
        }
//    }
}

void TopViewDelegate::controlMaunal2ModeSlot()
{
    //qDebug()<<"maunal2mode";
    if(EM_CONTROL_MODE_T2==globalData->globalHandState)
    {
        return;
    }

//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState != ENUM_COMMAND_RUN && globalData->globalCurrentState != ENUM_COMMAND_CEASE)
        {
            emit setControlMaunalMode(EM_CONTROL_MODE_T2);
//            if(globalData->globalHandState == EM_CONTROL_MODE_AUTO || globalData->globalHandState == EM_CONTROL_MODE_EXT)
//            {
//                emit manualChangeSignal(0);
//            }
//            globalData->unlock();
        }
        else
        {
//            globalData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请停止程序再切换T2模式"));
        }
//    }
}

void TopViewDelegate::controlAutoModeSlot()
{
    //qDebug()<<"automode";
    if(EM_CONTROL_MODE_AUTO==globalData->globalHandState)
    {
        return;
    }

//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState != ENUM_COMMAND_RUN && globalData->globalCurrentState != ENUM_COMMAND_CEASE)
        {
//            globalData->unlock();
            emit setControlMaunalMode(EM_CONTROL_MODE_AUTO);
            //emit manualChangeSignal(1);
        }
        else
        {
//            globalData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请停止程序再切换自动模式"));
        }
//    }
}

void TopViewDelegate::controlExtraModeSlot()
{
    //qDebug()<<"extramode";
    if(EM_CONTROL_MODE_EXT==globalData->globalHandState)
    {
        return;
    }
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState != ENUM_COMMAND_RUN && globalData->globalCurrentState != ENUM_COMMAND_CEASE)
        {
//            globalData->unlock();
            emit setControlMaunalMode(EM_CONTROL_MODE_EXT);
            //emit manualChangeSignal(1);
        }
        else
        {
//            globalData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请停止程序再切换外部模式"));
        }
//    }
}

void TopViewDelegate::controlFleetModeSlot()
{
    if(EM_CONTROL_MODE_FLEET==globalData->globalHandState)
    {
        return;
    }
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState != ENUM_COMMAND_RUN && globalData->globalCurrentState != ENUM_COMMAND_CEASE)
        {
//            globalData->unlock();
            emit setControlMaunalMode(EM_CONTROL_MODE_FLEET);
            //emit manualChangeSignal(1);
        }
        else
        {
//            globalData->unlock();
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请停止程序再切换调度模式"));
        }
//    }
}

void TopViewDelegate::changeJointCoordinateSlot()//手动坐标系
{
    //qDebug()<<"jointcoordinate";
    emit setJointCoordinateSignal(EM_JOG_COORDINATE_JOINT);
}

void TopViewDelegate::changeUserCoordinateSlot()
{
    //qDebug()<<"usercoordinate";
    emit setJointCoordinateSignal(EM_JOG_COORDINATE_USER);
}

void TopViewDelegate::changeToolCoordinateSlot()
{
    //qDebug()<<"toolcoordinate";
    emit setJointCoordinateSignal(EM_JOG_COORDINATE_TOOL);
}

void TopViewDelegate::changeWorldCoordinateSlot()
{
    //qDebug()<<"worldcoordinate";
    emit setJointCoordinateSignal(EM_JOG_COORDINATE_WORLD);
    //topView->jogCoordinateView->updateCurrentJogDate();//2020.12.28 更新全部取消
}

void TopViewDelegate::showRobotListSlot()
{
    //qDebug()<<"robotlist";
    topView->robotListView->updateRobotView();//刷新
}

void TopViewDelegate::changeRobotSlot(int id)
{
    qDebug()<<"change id "<<id;
    int returnFlag;
    communicateNormal->changeCurrentRobotId( id, returnFlag);
    if(1!=returnFlag)
    {
        QMessageBox::information(NULL, "提示", "切换失败！", QMessageBox::Yes );
        return;
    }

    emit robotChanged_signal();

    fileData.initFileData();//清空文件数据(存在情况:若切换机器人,切换IP地址等)


//    globalData->currentRobotID = id;//重新初始化机器人信息(这个涉及文件地址获取)
    globalData->gsoapCtrlState = EM_UPDATE_STATUS_LV1;//若是切换角色,则是代表 重新回到LV1(初始登录无实际用处)
    globalData->controllerIsConnected = EM_CONNECT_SUCCESS;//并非断线重连,不需要重新ID设为0
    globalData->globalLoginStatus = true;

    ioData->currentRobotID = id;//重新初始化机器人信息(这个涉及文件地址获取)
    ioData->gsoapCtrlState = EM_UPDATE_STATUS_LV1;//若是切换角色,则是代表 重新回到LV1(初始登录无实际用处)
    ioData->controllerIsConnected = EM_CONNECT_SUCCESS;//并非断线重连,不需要重新ID设为0
    ioData->globalLoginStatus = true;



}

void TopViewDelegate::showFileNameSlot()
{
    //qDebug()<<"filename";
}

void TopViewDelegate::homeMenuSlot()
{
    //qDebug()<<"homeMenu";
    emit changeViewIDsignal(MID_HOME_MENU);
}



void TopViewDelegate::changeAccountSlot()
{
    qDebug()<<"account";
    topView->account=EM_ACCOUNT_USER;
}

//void TopViewDelegate::initNewCoordSlot()
//{
//    //if(initCoordinateFlag)
//    //{

//    //}
//}

void TopViewDelegate::initialValue()
{
        topView->controlMode=EM_CONTROL_MODE_T1;
        topView->autoSpeed=2;
        topView->maunalSpeed=2;
        topView->debugMode=EM_DEBUG_MODE_STEP;
        topView->ipoModeFlag=0;
        topView->jogCoordinate=EM_JOG_COORDINATE_JOINT;
        topView->currentToolCoordinate=1;
        topView->currentUserCoordinate=1;

        topView->account=EM_ACCOUNT_ADMIN;

        topView->shortMessage="information";
        topView->longMessage=tr("--------------");
        topView->fileName="program";

        topView->motorStatus=EM_MOTOR_STATUS_SERVO_ON;

//        RobotInformation robotInfo;
//        robotInfo.RobotId=1001;
//        robotInfo.RobotName="kuka";
//        topView->robotList.append(robotInfo);
//        robotInfo.RobotId=1002;
//        robotInfo.RobotName="fanuc";
//        topView->robotList.append(robotInfo);
}

void TopViewDelegate::changeLanguageSlot(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/topViewDelEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    topView->changeLanguage(language);
}
